import { Element } from 'diagram-js/lib/model/Types';
import modelerStore from '@wf/components/bpmnjs/store/modeler';
import BpmnReplace from 'bpmn-js/lib/features/replace/BpmnReplace';
import { is } from 'bpmn-js/lib/util/ModelUtil';

// 切换子流程为事务或非事务
export function switchSubProcessTransaction(element: Element, toTransaction: Boolean) {
  let type = 'bpmn:SubProcess';
  if (toTransaction && is(element, 'bpmn:SubProcess')) {
    type = 'bpmn:Transaction';
  } else if (!toTransaction && is(element, 'bpmn:Transaction')) {
    type = 'bpmn:SubProcess';
  }

  // 假设你已经有了bpmnModeler实例
  const store = modelerStore();
  const { replaceElement } = store.getModeler.get<BpmnReplace>('bpmnReplace');
  replaceElement(element, { type });
}
